<?php
/* SVN FILE: $Id$ */
/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @version       $Revision$
 * @modifiedby    $LastChangedBy$
 * @lastmodified  $Date$
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * Short description for class.
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller {
    
	 var $helpers = array('Html','Form','Ajax','Javascript');
	 var $components = array('Session', 'Email');
	
    
    public function beforeFilter() {
        parent::beforeFilter();
    }
    
	 public function b_fCheckLogin()
	 {
	 	$User = $this->Session->read('User.User');
	 	if( !$User)
	 	{
	 		$this->redirect(array('controller'=>'pages','action'=>'display'));
	 	}
	 		
	 }
	 public function sendMail( $data = null )
	 {
	 	$this->Email->from = 'chienthuatxd@gmail.com';
	 	if ( $data['from'] )
	 		$this->Email->from = $data['from'];  

		$this->Email->subject = $data['subject'];  
		$this->Email->to = $data['to'];
		$this->Email->sendAs = 'both';
		try {
			$this->Email->send($data['content']);
		} 
		catch ( Exception $e)
		{
			echo $e->getMessage();	
		}
		
	 }
     
       //function outputs upload error messages, http://www.php.net/manual/en/features.file-upload.errors.php#90522
  function upload_errors($err_code) {
    switch ($err_code) { 
        case UPLOAD_ERR_INI_SIZE: 
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 
        case UPLOAD_ERR_FORM_SIZE: 
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 
        case UPLOAD_ERR_PARTIAL: 
            return 'The uploaded file was only partially uploaded'; 
        case UPLOAD_ERR_NO_FILE: 
            return 'No file was uploaded'; 
        case UPLOAD_ERR_NO_TMP_DIR: 
            return 'Missing a temporary folder'; 
        case UPLOAD_ERR_CANT_WRITE: 
            return 'Failed to write file to disk'; 
        case UPLOAD_ERR_EXTENSION: 
            return 'File upload stopped by extension'; 
        default: 
            return 'Unknown upload error'; 
    } 
   }

	function getExtension($str) {
	         $i = strrpos($str,".");
	         if (!$i) { return ""; }
	         $l = strlen($str) - $i;
	         $ext = substr($str,$i+1,$l);
	         return $ext;
	 }
}
?>